%     AERO LOAD - программа для нагружения агрегатов самолета распределенной нагрузкой
%     Copyright (C) 2018-2024  Михаил Козлов
%     Сайт проекта: <http://www.fastenerdoctor.ru/>
%     Адрес электронной почты для связи с разработчиком:
%     <doctor.fastener@gmail.com>
% 
%     Эта программа является свободным программным обеспечением: Вы можете
%     распространять ее и/или изменять, соблюдая условия Универсальной общественной
%     лицензии GNU, опубликованной Фондом свободного программного обеспечения,
%     либо редакции 3, либо (на Ваше усмотрение) любой редакции, выпущенной позже.
% 
%     Эта программа распространяется в надежде на то, что она окажется полезной,
%     но БЕЗ КАКИХ-ЛИБО ГАРАНТИЙ, включая даже подразумеваемую гарантию ТОВАРНОЙ ПРИГОДНОСТИ,
%     либо ПРИГОДНОСТИ ДЛЯ ОПРЕДЕЛЕННЫХ ЦЕЛЕЙ. Ознакомьтесь с Универсальной общественной
%     лицензией GNU для получения более подробной информации.
% 
%     Вы должны были получить копию Универсальной общественной лицензии GNU
%     вместе с этой программой. Если Вы ее не получили, то перейдите по адресу:
%     <http://www.gnu.org/licenses/>.
% 
%     This program is free software: you can redistribute it and/or modify
%     it under the terms of the GNU General Public License as published by
%     the Free Software Foundation, either version 3 of the License, or
%     (at your option) any later version.
% 
%     This program is distributed in the hope that it will be useful,
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
%     GNU General Public License for more details.
% 
%     You should have received a copy of the GNU General Public License
%     along with this program.  If not, see <https://www.gnu.org/licenses/>.

function Load = Read_Distributions(Load)

global ErrCode;

if (strcmp(Load.Span_Load.Law, 'LOAD_DIAGRAM'))
    
    Load.Span_Load.Load_Diagram_Data = Read_Distribution_File(Load.Span_Load.Load_Diagram_File_Name);
    
    if (ErrCode < 0)
        return;
    end
    
end

switch Load.Chord_Pressure.Law
    
    case 'USER_MODEL'
        
        Load.Chord_Pressure.User_Model_Data = Read_User_Model(Load.Chord_Pressure.User_Model_File_Name);

        if (ErrCode < 0)
            return;
        end
        
    case 'TRAPEZOID'
        
        if (strcmp(Load.Chord_Pressure.Trapezoid_Xd_Type, 'DISTRIBUTION'))

            Load.Chord_Pressure.Trapezoid_Xd_Distr_Data = Read_Distribution_File(Load.Chord_Pressure.Trapezoid_Xd_Distr_File_Name);

            if (ErrCode < 0)
                return;
            end

        end
        
    case {'MODEL_1', 'MODEL_3', 'MODEL_15'}
        
        if (strcmp(Load.Chord_Pressure.Model_X_p2_p1_Type, 'DISTRIBUTION'))

            Load.Chord_Pressure.Model_X_p2_p1_Distr_Data = Read_Distribution_File(Load.Chord_Pressure.Model_X_p2_p1_Distr_File_Name);

            if (ErrCode < 0)
                return;
            end

        end
        
        if (strcmp(Load.Chord_Pressure.Model_X_f_Type, 'DISTRIBUTION'))

            Load.Chord_Pressure.Model_X_f_Distr_Data = Read_Distribution_File(Load.Chord_Pressure.Model_X_f_Distr_File_Name);

            if (ErrCode < 0)
                return;
            end

        end
        
    case 'MODEL_2'
        
        if (strcmp(Load.Chord_Pressure.Model_X_p2_p1_Type, 'DISTRIBUTION'))

            Load.Chord_Pressure.Model_X_p2_p1_Distr_Data = Read_Distribution_File(Load.Chord_Pressure.Model_X_p2_p1_Distr_File_Name);

            if (ErrCode < 0)
                return;
            end

        end
        
        if (strcmp(Load.Chord_Pressure.Model_X_p3_p1_Type, 'DISTRIBUTION'))

            Load.Chord_Pressure.Model_X_p3_p1_Distr_Data = Read_Distribution_File(Load.Chord_Pressure.Model_X_p3_p1_Distr_File_Name);

            if (ErrCode < 0)
                return;
            end

        end
        
        if (strcmp(Load.Chord_Pressure.Model_X_f_Type, 'DISTRIBUTION'))

            Load.Chord_Pressure.Model_X_f_Distr_Data = Read_Distribution_File(Load.Chord_Pressure.Model_X_f_Distr_File_Name);

            if (ErrCode < 0)
                return;
            end

        end
        
    case {'MODEL_4', 'MODEL_10'}
        
        if (strcmp(Load.Chord_Pressure.Model_X_f_Type, 'DISTRIBUTION'))

            Load.Chord_Pressure.Model_X_f_Distr_Data = Read_Distribution_File(Load.Chord_Pressure.Model_X_f_Distr_File_Name);

            if (ErrCode < 0)
                return;
            end

        end
        
    case 'MODEL_5'
        
        % Ничего не требуется
        
    case {'MODEL_6', 'MODEL_8', 'MODEL_14'}
        
        if (strcmp(Load.Chord_Pressure.Model_X_p2_p1_Type, 'DISTRIBUTION'))

            Load.Chord_Pressure.Model_X_p2_p1_Distr_Data = Read_Distribution_File(Load.Chord_Pressure.Model_X_p2_p1_Distr_File_Name);

            if (ErrCode < 0)
                return;
            end

        end
        
        if (strcmp(Load.Chord_Pressure.Model_X_f1_Type, 'DISTRIBUTION'))

            Load.Chord_Pressure.Model_X_f1_Distr_Data = Read_Distribution_File(Load.Chord_Pressure.Model_X_f1_Distr_File_Name);

            if (ErrCode < 0)
                return;
            end

        end
        
        if (strcmp(Load.Chord_Pressure.Model_X_f2_Type, 'DISTRIBUTION'))

            Load.Chord_Pressure.Model_X_f2_Distr_Data = Read_Distribution_File(Load.Chord_Pressure.Model_X_f2_Distr_File_Name);

            if (ErrCode < 0)
                return;
            end

        end
        
    case {'MODEL_7', 'MODEL_11', 'MODEL_13'}
        
        if (strcmp(Load.Chord_Pressure.Model_X_p2_p1_Type, 'DISTRIBUTION'))

            Load.Chord_Pressure.Model_X_p2_p1_Distr_Data = Read_Distribution_File(Load.Chord_Pressure.Model_X_p2_p1_Distr_File_Name);

            if (ErrCode < 0)
                return;
            end

        end
        
        if (strcmp(Load.Chord_Pressure.Model_X_p3_p1_Type, 'DISTRIBUTION'))

            Load.Chord_Pressure.Model_X_p3_p1_Distr_Data = Read_Distribution_File(Load.Chord_Pressure.Model_X_p3_p1_Distr_File_Name);

            if (ErrCode < 0)
                return;
            end

        end
        
        if (strcmp(Load.Chord_Pressure.Model_X_f1_Type, 'DISTRIBUTION'))

            Load.Chord_Pressure.Model_X_f1_Distr_Data = Read_Distribution_File(Load.Chord_Pressure.Model_X_f1_Distr_File_Name);

            if (ErrCode < 0)
                return;
            end

        end
        
        if (strcmp(Load.Chord_Pressure.Model_X_f2_Type, 'DISTRIBUTION'))

            Load.Chord_Pressure.Model_X_f2_Distr_Data = Read_Distribution_File(Load.Chord_Pressure.Model_X_f2_Distr_File_Name);

            if (ErrCode < 0)
                return;
            end

        end
        
    case 'MODEL_9'
        
        if (strcmp(Load.Chord_Pressure.Model_X_f1_Type, 'DISTRIBUTION'))

            Load.Chord_Pressure.Model_X_f1_Distr_Data = Read_Distribution_File(Load.Chord_Pressure.Model_X_f1_Distr_File_Name);

            if (ErrCode < 0)
                return;
            end

        end
        
        if (strcmp(Load.Chord_Pressure.Model_X_f2_Type, 'DISTRIBUTION'))

            Load.Chord_Pressure.Model_X_f2_Distr_Data = Read_Distribution_File(Load.Chord_Pressure.Model_X_f2_Distr_File_Name);

            if (ErrCode < 0)
                return;
            end

        end
        
    case 'MODEL_12'
        
        if (strcmp(Load.Chord_Pressure.Model_X_p2_p1_Type, 'DISTRIBUTION'))

            Load.Chord_Pressure.Model_X_p2_p1_Distr_Data = Read_Distribution_File(Load.Chord_Pressure.Model_X_p2_p1_Distr_File_Name);

            if (ErrCode < 0)
                return;
            end

        end
        
        if (strcmp(Load.Chord_Pressure.Model_X_p3_p1_Type, 'DISTRIBUTION'))

            Load.Chord_Pressure.Model_X_p3_p1_Distr_Data = Read_Distribution_File(Load.Chord_Pressure.Model_X_p3_p1_Distr_File_Name);

            if (ErrCode < 0)
                return;
            end

        end
        
        if (strcmp(Load.Chord_Pressure.Model_X_p4_p1_Type, 'DISTRIBUTION'))

            Load.Chord_Pressure.Model_X_p4_p1_Distr_Data = Read_Distribution_File(Load.Chord_Pressure.Model_X_p4_p1_Distr_File_Name);

            if (ErrCode < 0)
                return;
            end

        end
        
        if (strcmp(Load.Chord_Pressure.Model_X_f1_Type, 'DISTRIBUTION'))

            Load.Chord_Pressure.Model_X_f1_Distr_Data = Read_Distribution_File(Load.Chord_Pressure.Model_X_f1_Distr_File_Name);

            if (ErrCode < 0)
                return;
            end

        end
        
        if (strcmp(Load.Chord_Pressure.Model_X_f2_Type, 'DISTRIBUTION'))

            Load.Chord_Pressure.Model_X_f2_Distr_Data = Read_Distribution_File(Load.Chord_Pressure.Model_X_f2_Distr_File_Name);

            if (ErrCode < 0)
                return;
            end

        end
        
    otherwise
        
        fprintf (1, 'Ошибка функции Read_Distributions: недопустимое значение параметра Chord_Pressure_Law !\n');
        ErrCode = -1;
        return;
    
end
